closeDiv();

//select 基础模拟 !-important 禁止写具体业务 -!
$(".dropdown-menu li").click(function(){
	var bText = $(this).text();
	var bValue = $(this).attr('value');
	$(this).parent().siblings('.dropdown-toggle').text("");
	var $span = "<span></span>";
	$(this).parent().siblings('.dropdown-toggle').append($span);
	$(this).parent().siblings('.dropdown-toggle').find('span').text(bText);
	$(this).parent().parent().find('input[type="hidden"]').val(bValue);
	$(this).parent().css("display", "none");
 });

var xingmingsj;
var pageNo;
var dingweiid;
var dwpanduan=true;
var dingwei;
var pageNumber=1;
var jinyongbz = '';
function getCanshu(predingweiid,prepageNo,prexingmingsj, prejinyongbz){
	if(pageNo != 'null'&&pageNo != null){
		pageNumber=prepageNo;
		dingweiid=predingweiid;
		xingming=prexingmingsj;
		jinyongbz = prejinyongbz;
		$('#shoujihm').val(xingming);
		$('#yg-jinyongbz').val(jinyongbz);
		if (jinyongbz == '') {
			$('#yg-jinyongbzwz').text('全部');
		} else if (jinyongbz == 1) {
			$('#yg-jinyongbzwz').text('启用');
		} else if (jinyongbz == 0) {
			$('#yg-jinyongbzwz').text('禁用');
		}
	}
	showYuangong();
}
// 查询禁用启用
$('#a-yuangong-status li').click(function () {
	xingming = $('#shoujihm').val();
	jinyongbz = $('#yg-jinyongbz').val();
	showYuangong();
	return false;
});

var xingming = ""; 
//清除条件
$("#ry-reset").click(function(){
	$('#shoujihm').val("");
	$('#yg-jinyongbz').val("");
	$('.dropdown-toggle span').text("全部");
	pageNumber = 1;
	xingming = '';
	jinyongbz = '';
	dwpanduan=false;
	showYuangong();
	return false; 
});

$("#ry-add").click(function(){
	$("#cedan").load(path+"xjyuangong.jsp");
	return false; 
});

//查询按钮
$("#ry-search").click(function(){
	xingming = $.trim($('#shoujihm').val());
	jinyongbz = $('#yg-jinyongbz').val();
	pageNumber=1;
	dwpanduan=false;
    showYuangong();
    return false; 
});

//数据读取
function showYuangong() {
	var totalNumber=0;
    var params={
        "xingming": xingming,
        "jinyongbz": jinyongbz
    };
    $.ajax({
        type: "POST",
        url: path + "/yuangong/getCount",
        data: params,
        async: false,
        success: function(data){
	    	totalNumber = data;
			if(totalNumber==0){
				$(".c-height").css("display","none");
				$("#yuangongxx-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			}else{
				$(".c-height").css("display","block");
				$("#yuangongxx-img").html("");
			}
    	}
    });
    function getYuangong(name){
    	$('#tbyuangong').html('');
    	var container = $('#pagination-'+name);
		container.pagination({
		dataSource:'./yuangong/getByPage?xingming='+encodeURI(xingming) + '&jinyongbz='+encodeURI(jinyongbz),
		locator: '',
		pageSize: 12,
		pageNumber:pageNumber,
		totalNumber: totalNumber,
		showNavigator: true,
   	    formatNavigator: '共 <%= totalNumber %> 条',
		callback: function(data, pagination){
			var content = '';
			console.log(data)
            $.each(data,function(index,value){
            	 if(data[index].jinyongbz==0 ){
            		 var zt="启用";
                 }else if(data[index].jinyongbz==1){
                	 var zt="禁用";
                 }
            	 if(zt=="启用" ){
            		 var szt="禁用";
                 }else if(zt=="禁用"){
                	 var szt="启用";
                 }
            	 if(data[index].xingbie==1){
                	 var sex="男";
                 }else if(data[index].xingbie==2){
                	 var sex="女";
                 }else{
                	 var sex="";
                 }
                content+="<tr id="+this.id+">";
                content=content+'<td width="6%" >'+(((pagination.pageNumber-1)*pagination.pageSize)+index+1)+'</td>';
                content=content+'<td width="10%" >' +data[index].shoujihm + "</td>" ;
                content=content+'<td width="10%" >' +data[index].xingming + "</td>" ;
                content=content+'<td width="5%" >' +sex + "</td>" ;
                content=content+'<td width="10%" >' +data[index].yishengbm + "</td>" ;
                content=content+'<td width="10%" >' +szt + "</td>" ;
                content=content+'<td width="10%" >' + common_util.nullToEmpty(this.keshimc)+ "</td>" ;
                if(data[index].menzheng=="1"){
                    content=content+ '<td  width="6%"><span class="glyphicon  icon-check"></span></td>';
                }else{
                    content=content+ '<td  width="6%"></td>';
                }
                if(data[index].shouyao=="1"){
                    content=content+ '<td  width="6%"><span class="glyphicon   icon-check"></span></td>';
                }else{
                    content=content+ '<td  width="6%"></td>';
                }
                if(data[index].shouyin=="1"){
                    content=content+ '<td  width="6%"><span class="glyphicon   icon-check"></span></td>';
                }else{
                    content=content+ '<td  width="6%"></td>';
                }
                if(data[index].tongji=="1"){
                    content=content+ '<td  width="6%"><span class="glyphicon   icon-check"></span></td>';
                }else{
                    content=content+ '<td  width="6%"></td>';
                }
                if( data[index].huanzhe=="1"){
                    content=content+ '<td  width="6%"><span class="glyphicon   icon-check"></span></td>';
                }else{
                    content=content+ '<td  width="6%"></td>';
                }
                if(data[index].gly=="1"){
                    content=content+ '<td  width="6%"><span class="glyphicon   icon-check"></span></td>';
                }else{
                    content=content+ '<td  width="6%"></td>';
                }
                content=content+'<td class= width="10%"><a class="operation-left"  id="'+data[index].id+'" onclick="toXiangqing('+data[index].id+','+pagination.pageNumber+')">详情</a>';
                content=content+'<a class="operation-right" value="'+zt+'" index="'+data[index].id+'" onclick="jingyongbz('+data[index].id+','+data[index].shifoulb+',$(this))">'+zt+'</a></td>';
                content=content+"</tr>";
                if(dingweiid==this.id){
                	dingwei=this.id;
                }
            });
            $("#tbyuangong").html(content);
            //查询状态定位Fjh
        	if(dingwei!=null&&dingwei!=''){
 	        	$('#tbyuangong').find('tr[id="'+dingwei+'"]').addClass('list-tr');
        	}
			//点击查询按钮和重置按钮定位状态消失
        	if(!dwpanduan){
        		$('#tbyuangong').find('tr[id="'+dingwei+'"]').removeClass('list-tr');
       	 	}
         }
    });
	 return container;
    }
    getYuangong('fenyyg');
	if(totalNumber <= 12) {
		$('#pagination-fenyyg').css('display','none');
	}else{
		$('#pagination-fenyyg').css('display','block');
	}
}
var row_id = 0;
function jingyongbz(id,sf,$this){
	$this.parent().parent().siblings('tr').removeClass('list-tr');
	row_id= id;
	 if($(".operation-right[index='"+id+"']").attr("value")== "禁用" ){
		 if(sf==0){
			 $("#awaken").modal();
		 }else if(sf==1){
	    	 $("#prohibit-gly").modal();
	     }    	
     }else if($(".operation-right[index='"+id+"']").attr("value")== "启用"  ){
    	 $("#prohibit").modal();
     }	 
}

//弹出框确认
$(document).on("click",".confirm",function(){
	confrim();
});

function toXiangqing(id,prepageNo){
	var prexingmingsj=$.trim($('#shoujihm').val());
	prexingmingsj=encodeURI(encodeURI(prexingmingsj));
	$("#cedan").load(path+"/views/zhensuo/yuangongxq.jsp?ID="+id+"&pageNo="+prepageNo+"&xingmingsj="+prexingmingsj +"&jinyongbz="+jinyongbz);
	return false; 
}

//弹出框
function confrim(){
	 if($(".operation-right[index='"+row_id+"']").attr("value")== "禁用" ){
         var jinyongbz=0;
     }
     else if($(".operation-right[index='"+row_id+"']").attr("value")== "启用"  ){
    	 var jinyongbz=1;
     }
	 var sendData1 ={
		 "id":row_id,
		 "jinyongbz":jinyongbz
	 };
	  $.ajax({
	        //请求方式为get
	        type:"POST",
	        //获取json文件路径
	        url:"./yuangong/jinyongyg",
	        //传送数据
	        data:sendData1,
	        //请求成功完成后要执行的方法
	        success: function(data){
	        	 $("#prohibit").modal('hide');
	        	 $("#awaken").modal('hide');
	        	 showYuangong();
	        }
	    });
	  return false;
}